package com.megurokai.tool;

import com.megurokai.paint.PaintManager;

import android.view.MotionEvent;
import android.view.ScaleGestureDetector;

public class ToolZoom implements Tool {
	protected PaintManager manager;
	protected float spanBegin;
	protected float zoomBegin;
	
	public ToolZoom(PaintManager manager){
		this.manager = manager;
	}
	
	@Override
	public boolean onToudhDown(MotionEvent event) {
		// 何もしない
		return false;
	}

	@Override
	public boolean onTouchUp(MotionEvent event) {
		// 何もしない
		return false;
	}

	@Override
	public boolean onTouchMove(MotionEvent event) {
		// 何もしない
		return false;
	}

	@Override
	public boolean onScale(ScaleGestureDetector detector) {
		float spanRate = detector.getCurrentSpan() / spanBegin;
		manager.setZoomRate(zoomBegin * spanRate);
		return true;
	}

	@Override
	public boolean onScaleBegin(ScaleGestureDetector detector) {
		manager.setLock(true);
		spanBegin = detector.getCurrentSpan();
		zoomBegin = manager.getZoomRate();
		return true;
	}

	@Override
	public boolean onScaleEnd(ScaleGestureDetector detector) {
		manager.setLock(false);
		return true;
	}

}
